package com.carlinfo.controller.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.carlinfo.common.util.ConstantFinalUtil;
import com.carlinfo.users.pojo.AAdmin;

/**
 * 登陆拦截
 * @author l1103
 *
 */
public class AuthFilter implements Filter {

	@Override
	public void init(FilterConfig config) throws ServletException {

	}

	@Override
	public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
			throws IOException, ServletException {
		ConstantFinalUtil.LOGGER.info("====AuthFilter====");
		HttpServletRequest request = (HttpServletRequest) req ; 
		HttpServletResponse response = (HttpServletResponse) resp ;
		HttpSession session = request.getSession() ; 
		//chain.doFilter(request, response);
		 //检查session是否有值 
		AAdmin admin = (AAdmin) session.getAttribute("admin");
		if(admin != null)
		{
			chain.doFilter(request, response);
			return ; 
		}
		response.sendRedirect(request.getContextPath()+"/admin/login.htm");
	}

	@Override
	public void destroy() {
		
	}
	

}
